from qiniu import Auth, put_data

access_key = 'YbTwmmgmGMhUuLAvdKnEz3yIUfd7yKObC-Evz8cz'
secret_key = 'NUmwljqIRfle9iVIiVP9wLN0R0uz-HwlmL5OA-FN'

bucket_name = 'test'


def storage(data):
    try:
        q = Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        ret, info = put_data(token, None, data)
        print(ret, info)
    except Exception as f:
        raise f
    if info.status_code != 200:
        raise Exception
    return ret["key"]


if __name__ == '__main__':
    file = input("请输入文件路径: ")
    with open(file, "rb") as f:
        storage(f.read())
